package com.example.demo03datajdbc.controller;

import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;
import java.util.Map;

@Controller
public class HelloController {

    private final JdbcTemplate template;

    public HelloController(JdbcTemplate template) {
        this.template = template;
    }

    @RequestMapping(path = "/users")
    @ResponseBody
    public List<Map<String, Object>> users() {
        List<Map<String, Object>> maps = template.queryForList("SELECT id, name, age FROM user");
        return maps;
    }

}
